<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="sealte.hvpms.pojo.*,sealte.hvpms.dao.impl.*,sealte.hvpms.util.HVPMSTools,java.util.Iterator" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>仓鼠网上投票系统HVPMS</title>
<link href="css/vp_view_frame.jsp.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="js/vp_view_frame.js" type="text/javascript"></script>
</head>
<body>
<%
	UserCreate uc = (UserCreate)session.getAttribute("UserCreate");
	if(uc!=null){
		String id_str = request.getParameter("id");
		if(id_str!=null&&!id_str.equals("")&&HVPMSTools.isNum(id_str)){
			int id = Integer.parseInt(id_str);
			Poll poll = (new PollDAOImpl()).getPoll(id);
			int max = poll.getMaxanswers();
			String name = poll.getName();
			Iterator<PollOption> iter = (new PollOptionDAOImpl()).getPOAll(id).iterator();
			StringBuffer sb = new StringBuffer();
			sb.append("<script type='text/javascript'>");
			sb.append("\n");
			sb.append("function validateToSubmit(){");
			sb.append("\n");
			sb.append("var i=0;var max="+max+";$(':checkbox').each(function(){if($(this).attr('checked')){i++}}); ");
			sb.append("\n");
			sb.append("if(i>0){if(i<max){$('#voteForm').submit();}else{alert('您最多只能选"+max+"项')}}else{alert('您还没选择投票项')}}</script>");
			sb.append("\n");
			sb.append(name+"[最多可选"+max+"项] ");
			sb.append("\n");
			sb.append("<form action='"+basePath+"VPVote' method='POST' id='voteForm'>");
			sb.append("\n");
			sb.append("<input type='hidden' name='fid' value='"+id+"'>");
			sb.append("\n");
			sb.append("<table>");
			sb.append("\n");
			sb.append("<tr><th>序号</th><th>选项</th><th>相关图片</th><th>相关链接</th></tr>");
			sb.append("\n");
			while(iter.hasNext()){
				PollOption po = iter.next();
				sb.append("<tr><td><input type='checkbox' name='poll_options' value='"+po.getId()+"'>"+po.getId()+"</td><td>"+po.getContent()+"</td><td><img src='"+po.getImage()+"' onload='proDownImage(this);'></td><td>"+po.getLink()+"</td></tr>");
				sb.append("\n");
			}
			sb.append("<tr><td colspan='4'><input type='button' value='提交' onclick='validateToSubmit()'></td></tr>");
			sb.append("\n");
			sb.append("</table></form>");
%>
<div id="num2">
<h2><img src="images/page.png">&nbsp;投票信息管理--查看</h2>
</div>
<div id="num1">
	<table id="table_control">
	<tr>
		<td>
		<input type="button" value="投票信息" onclick="showRefArea(1)">
		<input type="button" value="站外引用" onclick="showRefArea(2)">
		<input type="button" value="返回" onclick="window.location.href='<%=basePath%>home/vp_management.jsp'">
		</td>
	</tr>
</table>
</div>
<div id="frameTopArea">
<table id="table_showLink">
	<tr>
		<th align="right">链接：</th>
		<td align="left">
		<input type="text" size="60" id="outSiteRefLink" readonly="readonly" value="<%=basePath+"vp_view.jsp?fid="+id%>">
		<input type="button" value="复制[链接]" onclick="doCopyLink(1)"><input type="button" value="复制[代码]" onclick="doCopyLink(2)">
		</td>
	</tr>
	<tr>
		<th align="right" valign="top">静态HTML代码：</th>
		<td align="left">
			<textarea cols="80" rows="15" readonly="readonly" id="outSiteRefCode"><%=sb.toString() %></textarea>
		</td>
	</tr>
</table>
</div>

<div id="vp_info">
<jsp:include page="../vp_view.jsp">
	<jsp:param name="fid" value="<%=id %>" />
</jsp:include>
</div>
<%	
		}else{
			out.println("系统出错，请联系开发者");
		}
	}else{
		out.println("谢绝跨路径访问！");
	}
%>
</body>
</html>